import { getDetails } from '@/modules/sys/api/user'

var validateUsername = (rule, value, callback) => {
  getDetails(value).then(response => {
    if (window.boxType === 'edit') callback()
    let result = response.data.data
    if (result !== null) {
      callback(new Error('用户名已经存在'))
    } else {
      callback()
    }
  })
}
export const tableOption = {
  border: true,
  index: true,
  indexLabel: '序号',
  labelWidth: 100,
  stripe: true,
  menuAlign: 'center',
  editBtn: false,
  delBtn: false,
  align: 'center',
  addBtn: false,
  height: 'auto',
	autoLoad: true,
  column: [{
    fixed: true,
    label: 'id',
    prop: 'id',
    span: 12,
    hide: true,
    editDisabled: true,
    addDisplay: false
  }, {
    fixed: false,
    label: '用户名',
    prop: 'username',
    editDisabled: true,
    slot: true,
    search: true,
    span: 12,
    rules: [{
      required: true,
      message: '请输入用户名'
    },
    {
      min: 3,
      max: 20,
      message: '长度在 3 到 20 个字符',
      trigger: 'blur'
    },
    { validator: validateUsername, trigger: 'blur' }
    ]
  }, {
    label: '密码',
    prop: 'password',
    type: 'password',
    value: '',
    hide: true,
    span: 12,
    editDisplay: false,
    addDisplay: true,
    rules: [{
      min: 6,
      max: 20,
      message: '长度在 6 到 20 个字符',
      trigger: 'blur'
    }]
  }, {
    label: '所属机构',
    prop: 'orgId',
    type: 'select',
    dicUrl: '/sys/org/companyList',
    //formsolt: true,
    cascaderItem: ['deptId'],
    span: 12,
    //hide: true,
    //valueDefault: '',
    rules: [{
      required: true,
      message: '请选择机构',
      trigger: 'blur'
    }]
  }, {
    label: '所属部门',
    prop: 'deptId',
    //formsolt: true,
    slot: true,
    type: 'select',
    dicFlag: false,
    dicUrl: '/sys/dept/deptList/{{key}}',
    span: 12,
    //hide: true,
    rules: [{
      required: true,
      message: '请选择部门',
      trigger: 'blur'
    }]
  }, {
    label: '角色',
    prop: 'role',
    type: 'select',
    formslot: true,
    slot: true,
    //dicFlag: false,
    //dicUrl: '/sys/role/roleList/{{key}}',
    overHidden: true,
    span: 12,
    rules: [{
      required: true,
      message: '请选择角色',
      trigger: 'blur'
    }]
  }, {
	    label: '机构权限',
	    prop: 'dataScope',
//	    formsolt: true,
//	    solt: true,
	    overHidden: true,
	    type: 'select',
	    span: 12,
	    rules: [{
	      required: true,
	      message: '请选择机构权限',
	      trigger: 'blur'
	    }],
	    dicUrl: '/dict/itemList/sys.user.dataScope',
	    props:{
	      value : 'value',
	      label : 'label'
	    }
    }, {
      label: '是否管理员',
      prop: 'isAdmin',
      type: 'switch',
      width : 120,
      solt: true,
      span: 12,
      valueDefault : false
    }, {
      label: '是否有效',
      prop: 'isActive',
      type: 'switch',
      slot: true,
      span: 12,
      valueDefault : true
      }, {
    label: '手机号',
    prop: 'mobile',
    value: '',
    span: 12,
    rules: [{
      min: 11,
      max: 11,
      message: '长度在 11 个字符',
      trigger: 'blur'
    }]
  }, {
    label: '固话',
    prop: 'phone',
    type: 'phone',
    value: '',
    span: 12,
    rules: [{
      min: 6,
      max: 20,
      message: '长度大于等于6个字符且小于等于20个字符',
      trigger: 'blur'
    }]
  }, {
    label: '邮件',
    prop: 'email',
    type: 'email',
    span: 12,
    rules: [{
      max: 30,
      message: '长度小于30个字符',
      trigger: 'blur'
    }]
  }, {
    label: '头像',
    prop: 'avatar',
    span: 12,
    rules: [{
      max: 255,
      message: '长度小于255个字符',
      trigger: 'blur'
    }]
  }, {
    label: '是否冻结',
    prop: 'isLocked',
    type: 'switch',
    slot: true,
    span: 12
  }, {
    width: 180,
    label: '冻结时间',
    prop: 'lockTime',
    type: 'datetime',
    format: 'yyyy-MM-dd HH:mm',
    valueFormat: 'yyyy-MM-dd HH:mm:ss',
    editDisabled: true,
    addDisplay: false,
    span: 12
  }, {
    width: 180,
    label: '创建时间',
    prop: 'createTime',
    type: 'datetime',
    format: 'yyyy-MM-dd HH:mm',
    valueFormat: 'yyyy-MM-dd HH:mm:ss',
    editDisabled: true,
    addDisplay: false,
    span: 12
  }, {
    label: '备注',
    prop: 'remark',
    type: 'textarea',
    span: 24,
    rules: [{
      max: 255,
      message: '长度小于255个字符',
      trigger: 'blur'
    }]
  }]
}
